﻿using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp.Modules.Core.Pages
{
    public partial class CodeDefinition_List : SsTemplatePage
    {
        public Guid SelCategoryId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            SelCategoryId = RequestUtility.GetGuid(Request, "category");

            _ctlLinkCreateCode.NavigateUrl = string.Format("~/Modules/Core/Pages/CodeDefinition-Create.aspx?categoryid={0}", SelCategoryId);
            if (!IsPostBack)
            {
                ICoreService service = ServiceLocator.Get<ICoreService>();
                List<CodeCategory> categories = service.GetCodeCategories();
                _ctlListCategory.DataSource = categories;
                _ctlListCategory.DataBind();

                if (SelCategoryId != Guid.Empty)
                {
                    List<CodeDefinition> codes = service.GetCodeDefinitions(SelCategoryId);
                    _ctlListCode.DataSource = codes;
                    _ctlListCode.DataBind();
                }
            }
        }
    }
}